package org.jks.service;

import java.util.List;

import org.jks.model.DeviceInOut;
import org.springframework.stereotype.Service;

@Service
public class DeviceInOutService extends EntityService<DeviceInOut>{
	
	public DeviceInOutService(){
		MODEL_NAME = DeviceInOut.class.getSimpleName();
		CLASS_NAME = DeviceInOut.class;
	}
	
	public List<DeviceInOut> all() {
		return find("from " + MODEL_NAME + " order by Time desc");
	}
	
	public List<DeviceInOut> search(String startTime, String endTime, int page, int pagesize){
		String hql = "from " + MODEL_NAME + " where 1=1";
		if(startTime != null && startTime.length() > 0){
			hql += " and Time >= '" + startTime + " 00:00:00'";
		}
		if(endTime != null && endTime.length() > 0){
			hql += " and Time <= '" + endTime + " 23:59:59'";
		}
		List<Object> params = null;
		return find(hql, params, page, pagesize);
	}
	
	public long countByCondition(String startTime, String endTime){
		String hql = "from " + MODEL_NAME + " where 1=1";
		if(startTime != null && startTime.length() > 0){
			hql += " and Time >= '" + startTime + " 00:00:00'";
		}
		if(endTime != null && endTime.length() > 0){
			hql += " and Time <= '" + endTime + " 23:59:59'";
		}
		List<DeviceInOut> t = find(hql);
		return t == null ? 0 : t.size();
	}
}
